<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no" />
		<title>首页</title>
		<link rel="stylesheet" type="text/css" href="../c/aui.css" />
		<style>
			.aui-card-list,
		.aui-card-list li,
		.aui-card-list ul,
		.aui-list .aui-list-item,
		.aui-list {
			background: none;
			border: 0;
			color: #fff;
		}

		#sx-view .aui-list-item-label-icon {
			color: #fff;
			font-size: 0.75rem;
		}

		#sx-view .aui-list-item-input input {
			color: #fff;
		}

		#sx-view .aui-list-item {
			border-bottom: 1px solid #222
		}

		#sx-view .aui-list-item:active {
			background: none
		}

		.img {
			position: relative;
		}

		.img span {
			position: absolute;
			right: 0;
			top: 0;
			height: 2.2rem;
			line-height: 2.2rem;
			padding: 0 1rem;
			border-left: 1px solid #222;
		}

		.img span img {
			width: 1.8rem;
			height: 1.8rem;
			display: inline-block;
			vertical-align: middle;
			margin-right: 0.75rem;
		}

		#sx-view .img span i {
			font-size: 0.6rem;
			margin-left: 0.35rem;
		}

		.sx-btn {
			background: #FE2C55;
			width: 80%;
			text-align: center;
			margin: 0 auto;
			padding: 0.55rem 0;
			border-radius: 0.25rem;
			margin-top: 1rem;
			font-size: 0.75rem;
		}

		.content {
			padding: 0.75rem;
			margin-top: 1rem;
			opacity: 0.7
		}

		.content .h2 {
			font-size: 0.75rem;
			padding-bottom: 0.35rem;
		}

		.content p {
			font-size: 0.7rem;
			padding: 0.15rem;
		}
		.sx-xieyi {
			text-align: center;
			color: #fff;
			font-size: 0.6rem;
			padding: 0.75rem 0;
			opacity: 0.75;
		}

		.sx-xieyi span {
			color: #FFB300;
			padding: 0 0.15rem;
			text-decoration: underline
		}
		.yqma{
			 position: fixed;
			 width: 90%;
			 left: 5%;
			 right: 5%;
			 border-radius: 0.5rem;
			 top: 25%;
			 background:#32376C;
		 }
		 .yqma p{
			 width: 100%;
			 color:#ffffff;
			     padding-top: 1rem;
			  text-indent: 3%;
			  padding-top: 0.5rem;
			} 
			.yqma input{
				width: 94%;
				margin: 0.5rem 0;
				border-radius: 0.3rem;
				color: #fff;
				height: 2rem;
				border: 0.01rem solid #fff;
				text-indent:0.5rem;
				background: none;
				margin-left: 3%;
				border: 0.01rem solid #fff;
			}
		.yqma button{
			background: #FE2C55;
			width: 40%;
			text-align: center;
			/* margin-left: 10%; */
			margin: 0 auto;
			padding: 0.55rem 0;
			border-radius: 0.25rem;
			
			margin-top: 1rem;
			font-size: 0.75rem;
			margin-left: 30%;
			margin-bottom: 1rem;
			color: #fff;
			border: none;
		}	
			.tcsyqm{
				position: absolute;
		        top: 0;
				right: 0;
				bottom: 0;
				left: 0;
				width: 100%;
				background: rgb(19,19,19);
				

			}
	</style>
	</head>
	<body>
		<div class="aui-content" id="sx-view">
			<ul class="aui-list aui-form-list">
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label-icon">
							手机号：
						</div>
						<div class="aui-list-item-input">
							<input type="tel" placeholder="填写已绑定手机号码" value="" id="mobile">
						</div>
					</div>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label-icon">
							验证码：
						</div>
						<div class="aui-list-item-input img">
							<input type="tel" placeholder="请输入手机验证码" value="" id="yzm">
							<span tapmode onclick="code()" class="sx-login-code-c">获取验证码</span>
						</div>
					</div>
				</li>
			</ul>
			<div class="sx-btn" tapmode onclick="_loginToken()">绑定并登录</div>
			<p class="sx-xieyi">
				登陆即代表您已阅读并同意<span tapmode onclick="_page('用户协议',1)">用户协议</span>和<span tapmode onclick="_page('隐私政策',2)">隐私政策</span>
			</p>
			<div class="content">
				<div>绑定说明：</div>
				<p>1.绑定手机可作为唯一的登录账户（不可修改）</p>
				<p>2.程度上保障账户安全，比如绑定、提现、实名认证等</p>
				<p>3.我们承诺不会向任何人透露您的个人信息</p>
			</div>
		</div>
		<div class="yqma" style="display: none;">
			<p>请输入邀请人的邀请码</p>
			<input type="text" placeholder="邀请码" class="yamiput" />
			<button onclick="surebtn()" class="surebtn">确定</button>
		</div>
	</body>
	<script type="text/javascript" src="../j/api.js"></script>
	<script src="../j/jquery-3.3.1.min.js"></script>
	<script type="text/javascript">
		var moduleSMSSDK;
		apiready = function() {
			urls();
			console.log(_getPrefs('_config').mob)
			if (_getPrefs('_config').mob == 1) {
				moduleSMSSDK = api.require('smssdk');
			}
			api.parseTapmode();
		}

		function _isMobile(phone) {
			if (!(/^1[123456789]\d{9}$/.test(phone))) {
				return false;
			} else {
				return true;
			}
		}
		var isinerval
		// 发送验证码
		function code() {
			if (times) {
				return _msg('不要重复操作')
			}
			_loading();
			var mobile = $('#mobile').val();
			mobile = $api.trimAll($api.trim(mobile));
			if (_isMobile(mobile)) {
				if (_getPrefs('_config').mob == 1) {
					var param = {
						zone: '86',
						phoneNumber: mobile,
						tempCode: _getPrefs('_config').sdkReg_id
					};
					moduleSMSSDK.getTextCode(param, function(ret, err) {
						if (err !== null && err !== undefined && err !== '') {
							_loadingCloes();
							// 错误消息示例：{"msg":"Template not exist.","code":484}
							return _msg(err.msg)
							console.log("Error:\n" + JSON.stringify(err));
						} else {
							_loadingCloes();
							_msg('验证码已发送')
							// 正常消息示例：{"smart":false}
							$('.sx-login-code-c').html('重新获取(120s)');
							times = 120;
							$('.sx-login-code-c').css('color', '#909090');
							isinerval = setInterval("CountDown()", 1000);
							document.getElementById("yzm").focus()
						}
					});
					return;
				}

				_ajax('user/code', function(ret, err) {
					_loadingCloes();
					if (ret) {
						console.log(JSON.stringify(ret));
						_msg(ret.ret ? ret.ret : ret.err);
						if (ret.ret) {
							$('.sx-login-code-c').html('重新获取(120s)');
							times = 120;
							$('.sx-login-code-c').css('color', '#909090');
							isinerval = setInterval("CountDown()", 1000);
							document.getElementById("yzm").focus()
						} else {
							_msg(ret.err)
						}
					} else {
						_alert(JSON.stringify(err));
					}
				}, {
					username: mobile,
					text: '绑定'
				})
			} else {
				_msg('手机号码格式错误');
				document.getElementById("mobile").focus()
			}
		}
		var times = 0;

		function CountDown() {
			times--;
			if (times < 1) {
				$('.sx-login-code-c').html('获取验证码');
				$('.sx-login-code-c').css('color', '#fff');
				clearInterval(isinerval);
				return;
			}
			$('.sx-login-code-c').html('重新获取(' + times + 's)');
		}
		var _root = 0;

		function _loginToken() {
			var mobile = $('#mobile').val();
			if (!mobile) {
				_msg('请输入手机号码');
				return document.getElementById("mobile").focus()
			}
			if (!_isMobile) {
				_msg('手机号码不正确');
				return document.getElementById("mobile").focus()
			}
			var yzm = $('#yzm').val();
			if (!yzm) {
				document.getElementById("yzm").focus()
				return _msg('请输入验证码');
			}

			if (_root) {
				return;
			}
			var json = {};
			var json1 = api.pageParam['data'];
			var json2 = {
				mobile: mobile,
				yzm: yzm
			};
			json = eval('(' + (JSON.stringify(json1) + JSON.stringify(json2)).replace(/}{/, ',') + ')');
			data = json;
			var bindStatus = data.bindStatus
			// return;
			_root = 1;
			_loading()
			_ajax('user/oauth_mobile', function(ret, err) {
				console.log(JSON.stringify(ret));
				_loadingCloes();
				if (ret) {
					if (ret.ret) {
						localStorage.setItem("token");
						_setPrefs('_token', ret.ret);
						localStorage.setItem("token",ret.ret);
						// 获取用户资料
						_ajax('member/info', function(ret, err) {
							if (ret) {
								var bind = localStorage.getItem("bind");
								if (bind == 0 || bind == "0") {
									$(".yqma").show();
									$(".surebtn").attr("name", ret.ret);
								} else {
									_setPrefs('_user', ret);
									_close();
								}
							}
						})
						// 获取用户资料
						// _ajax('member/info', function(ret, err) {
						// 	// console.log(JSON.stringify(ret));
						// 	var bind = localStorage.getItem("bind");
						// 	console.log(bind);
						// 	_loadingCloes();
						// 	if (ret) {
						// 		if (ret.err) {
						// 		} else {
						// 			_setPrefs('_token', ret.ret);
						// 			_setPrefs('_user', ret);
						// 			if (bind == 0 || bind == "0") {
						// 				// alert("ss");
						// 				$(".yqma").show();
						// 				$(".surebtn").attr("name", ret.ret);
						// 				break;
						// 			} else {
						// 				// alert("aaa");
						// 				// // 重新初始化融云
						// 				// api.execScript({
						// 				// 	name: 'root',
						// 				// 	script: 'rongyun_init()'
						// 				// });
						// 				// 如果当前用户没有被绑定并且有邀请用户主键id
						// 				if (bindStatus == 0 && fromUid==0) {
						// 					$(".yqma").show();
						// 					$(".surebtn").attr("name", ret.ret);
						// 					return;
						// 				} else {
						// 					// _close();
						// 				}
						// 				// window.location.href = "new_my.html";
						// 			}
						// 		}
						// 	}
						// })
					} else {
						_root = 0;
						return _msg(ret.err);
					}
				} else {
					console.log(JSON.stringify(err))
					_alert(err)
				}
				_root = 0;
			}, data)
		}

		// 请求绑定上下级
		function bindUser(fromUid) {
			console.log(fromUid)
			_ajax('renwu/yaoqing_yqm', function(ret, err) {
				// _close();
			}, {
				from_uid: fromUid
			})
		}
		function surebtn() {
			var token = $(".surebtn").attr("name")
			var yam = $(".yamiput").val();
			if (yam == "") {
				_msg("邀请码不能为空！");
			} else {
				yam=yam.replace(" ","");
				_ajax('renwu/yaoqing_code', function(ret, err) {
					console.log(JSON.stringify(ret));
					if (ret.code == "0" || ret.code == 0 && ret.code != undefined) {
						_ajax('member/info', function(ret, err) {
							if (ret) {


								_setPrefs('_user', ret);
								_close();

							}
						})
						_msg(JSON.stringify(ret.ret));
						_close();
					} else {
						_msg(JSON.stringify(ret.err))

					}

				}, {
					yq_code: yam
				})
			}
		}

		function closebtn() {
			// window.Location.href = "new_index.html";

		}
	</script>

</html>
